package CreationalPattern.Builder;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class XMLUtil {
    public static Object getBean() {
        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document document = documentBuilder.parse("src\\main\\resources\\config.xml");

            NodeList actorClassName = document.getElementsByTagName("ActorClassName");
            Node firstChild = actorClassName.item(0).getFirstChild();
            String nodeName = firstChild.getNodeValue();

            Class<?> name = Class.forName(nodeName);
            Object o = name.newInstance();
            return o;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }


    }
}
